<?php
echo $this->Html->addCrumb('Batches', '/admin/batches/index');
echo $this->Html->addCrumb('Parts', '/admin/parts/index/'.$part['Part']['batch_id']);
echo $this->Html->addCrumb('Questions', '/admin/questions/index/'.$part['Part']['id']);
echo $this->Html->addCrumb('Add Question');
?>
<div class="questions form">
<?php echo $this->Form->create('Question',array('action'=>'add/'.$part['Part']['id']));?>
	<fieldset>
		<legend><?php __('Admin Add Question'); ?></legend>
	<?php
		echo $this->Form->input('part_id',array('type'=>'hidden','value'=>$part['Part']['id']));
		echo $this->Form->input('question');            
		echo $this->Form->input('type',array('type'=>'hidden','value'=>$part['Part']['type']));
        if($part['Part']['type']=='options'){
//    		echo $this->Form->input('options',array('label'=>'Options (comma seperated values)','type'=>'text'));
			?>
			<div class="input">
			<label style="font-weight:bold;">Options</label>
			<p class="note">If the option is empty then textbox will be provided to user to fill the answer.</p>
			<span id="TextBoxesGroup">
				<div><span>Option 1</span><input type="text" id="QuestionOptions" name="data[Question][options][]"></div>
			</span>		
			<input type="button" id="addButton" value="Add Option" style="font-size:100%;padding:0px;width:auto;" />
			<input type="button" id="removeButton" value="Remove Option" style="font-size:100%;padding:0px;width:auto;" />
			</div>
			<?php
    		echo $this->Form->input('answer');            
        } 
        else 
        {            
    		echo $this->Form->input('options',array('type'=>'hidden','value'=>'none'));
    		echo $this->Form->input('answer',array('type'=>'hidden','value'=>'none'));
        }
		echo $this->Form->input('mark');
		echo $this->Form->input('instructions');
	?>
	</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>


<script type="text/javascript">
 
$(document).ready(function(){
 
    var counter = 2;
 
    $("#addButton").click(function () {
 
	if(counter>20){
            alert("Only 10 textboxes allow");
            return false;
	}    
	$('<div id="tb'+counter+'"><span>Option '+counter+'</span><input type="text" id="QuestionOptions_'+counter+'" name="data[Question][options][]"></div>').appendTo("#TextBoxesGroup");
 
 
	counter++;
     });
 
     $("#removeButton").click(function () {
	if(counter==1){
          alert("No more textbox to remove");
          return false;
       }   
 
	counter--;
 
        $("#tb" + counter).remove();
 
     });
 
     
  });
</script>
